package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;


public class FMouseMoveListener {
    public FMouseMoveListener(Element e, FMouseMoveHandler handler) {
        attachMouseMoveHandler(e, handler);
    }

    public static void setMouseMoveEvent(Element e, FMouseMoveHandler handler) {
        new FMouseMoveListener(e, handler);
    }

    private static native void dispatchMouseMoveHendler(JavaScriptObject event, FMouseMoveHandler handler) /*-{
    
            if (!event) event = $wnd.event;

            var x = event.clientX;
            var y = event.clientY;

            handler.@it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseMoveHandler::onMouseMove(II)(x,y);

            if (event.preventDefault)
                     event.preventDefault();
                 event.returnValue = false;
      }-*/;

    private native void attachMouseMoveHandler(Element e, FMouseMoveHandler handler) /*-{

         e.onmousemove = handler;

               if ($wnd.addEventListener && !$wnd.opera) {
                   e.addEventListener('onmousemove', @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseMoveListener::dispatchMouseMoveHendler(Lcom/google/gwt/core/client/JavaScriptObject;Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FMouseMoveHandler;), false);
               }

          e.onmousemove = function(event) {

                   @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseMoveListener::dispatchMouseMoveHendler(Lcom/google/gwt/core/client/JavaScriptObject;Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FMouseMoveHandler;)(event,handler);

          }

      }-*/;

}
